Skip to main content

Pure Pursuit: Tank

Same thing as the mecanum version of this module. Just make sure to replace the moveToPosition function with the one seen in tank drive part 2: ]

double xError = targetX - robotX;
double yError = targetY - robotY;
double theta = Math.atan2(yError,xError);

// 0 is the reference because we want the distance to go to 0
double distance = Math.hypot(xError, yError);

f = distanceController.calculate(0, distance);
t = angleController.calculate(theta, robotTheta);
// Range.clip is included in the SDK and will clip between two values
// angleController.error is a demonstrative attribute that gets the error.
f *= Math.cos(Range.clip(angleController.error, -PI/2, PI/2));

// set motor power here!
setRobotRelative(f,t);